// Copyright 2022 a.o.smith ALL Rights Reserved
package com.liuxinlong.modules.chimi.controller;

import com.liuxinlong.annotation.LogAnnotation;
import com.liuxinlong.constant.LogBusinessConstants;
import com.liuxinlong.constant.LogOperateConstants;
import com.liuxinlong.modules.chimi.controller.request.UpdateBarPointsConfigReq;
import com.liuxinlong.modules.chimi.service.BarPointsConfigService;
import com.liuxinlong.modules.common.controller.request.BaseDeleteReq;
import com.liuxinlong.modules.common.controller.request.BaseReq;
import com.liuxinlong.modules.common.controller.response.BaseResp;
import com.liuxinlong.modules.entity.BarPointsConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 论坛积分规则控制层
 * 
 * @author liuxinlong@hotwater.com.cn
 * @version 1.0.0
 * @since 2023-02-13
 */
@RestController
@RequestMapping("/points")
public class BarPointsConfigController {
	@Autowired
	private BarPointsConfigService barPointsConfigService;

	/**
	 * 分页查询积分规则信息
	 * 
	 * @param req 请求信息
	 * @return 积分规则信息列表
	 */
	@PostMapping("page")
//	@LogAnnotation(value ="分页查询",business = LogBusinessConstants.BAR_POINTS_CONFIG,operateType = LogOperateConstants.OPERATE_QUERY)
	public BaseResp pagePointsConfigInfo(@RequestBody BaseReq req) {
		Map<String,Object> queryParam = new HashMap<>();
		queryParam.put("startNum",req.getStartNum());
		queryParam.put("pageSize",req.getPageSize());
		List<Map<String,Object>> dataList = barPointsConfigService.pagePointsConfig(queryParam);
		int total = barPointsConfigService.getPointsConfigCount(queryParam);
		BaseResp resp = new BaseResp();
		resp.setDataList(dataList);
		resp.setTotalNum(total);
		resp.setRetMessage("分页查询积分规则信息成功");
		return resp;
	}

	/**
	 * 新增积分规则
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("add")
	@LogAnnotation(value ="新增积分规则",business = LogBusinessConstants.BAR_POINTS_CONFIG,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp addPointsConfig(@RequestBody UpdateBarPointsConfigReq req) {
		BarPointsConfig barPointsConfig = new BarPointsConfig();
		barPointsConfig.setDescription(req.getDescription());
		barPointsConfig.setPoints(req.getPoints());
		barPointsConfig.setSourceType(req.getSourceType());
		barPointsConfig.setType(req.getType());
		barPointsConfig.setStartTime(req.getStartTime());
		barPointsConfig.setEndTime(req.getEndTime());
		barPointsConfigService.addPointsConfig(barPointsConfig);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("新增积分规则成功");
		return resp;
	}

	/**
	 * 修改积分规则信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("update")
	@LogAnnotation(value ="修改积分规则信息",business = LogBusinessConstants.BAR_POINTS_CONFIG,operateType = LogOperateConstants.OPERATE_MODIFY)
	public BaseResp updatePointsConfig(@RequestBody UpdateBarPointsConfigReq req) {
		BarPointsConfig barPointsConfig = new BarPointsConfig();
		barPointsConfig.setId(req.getId());
		barPointsConfig.setDescription(req.getDescription());
		barPointsConfig.setPoints(req.getPoints());
		barPointsConfig.setSourceType(req.getSourceType());
		barPointsConfig.setType(req.getType());
		barPointsConfig.setStartTime(req.getStartTime());
		barPointsConfig.setEndTime(req.getEndTime());
		barPointsConfigService.updatePointsConfig(barPointsConfig);
		BaseResp resp = new BaseResp();
		resp.setRetMessage("修改积分规则信息成功");
		return resp;
	}

	/**
	 * 删除积分规则信息
	 * 
	 * @param req 请求信息
	 * @return 成功标识
	 */
	@PostMapping("delete")
	@LogAnnotation(value ="删除积分规则信息",business = LogBusinessConstants.BAR_POINTS_CONFIG,operateType = LogOperateConstants.OPERATE_DELETE)
	public BaseResp deletePointsConfig(@RequestBody BaseDeleteReq req) {
		barPointsConfigService.deletePointsConfig(req.getId());
		BaseResp resp = new BaseResp();
		resp.setRetMessage("删除积分规则信息成功");
		return resp;
	}

}
